package com.qianfeng.Event.listener;

import com.qianfeng.Event.DeviceStatusEvent;
import com.qianfeng.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/13 20:01
 */
@Component
public class DevliceStatusListener {
    private DeviceService deviceService;
    @Autowired
    public void setDeviceService(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @EventListener
    @Async
    public void onStatusChange(DeviceStatusEvent event){
        deviceService.updateDeviceStatus(event.getDeviceId(),event.getStatus()== DeviceStatusEvent.Status.OFFLINE ? 0 : 1);
    }
}
